package com.enzoism.springboot.juc;

import java.time.Instant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class MyThreadPoolExecutor4 {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService threadPoolExecutor = Executors.newWorkStealingPool();
        for (int i = 0; i < 20; i++) {
            threadPoolExecutor.execute(new MyRunable());
        }
        threadPoolExecutor.shutdown();
        threadPoolExecutor.awaitTermination(200, TimeUnit.SECONDS);
        System.out.println("----->线程结束退出");
    }

    private static class MyRunable implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("----->Current Thread Name:" + Thread.currentThread().getName() + " date:" + Instant.now());
        }
    }
}
